import { Component, OnInit,Output,Input,EventEmitter,ViewChild } from '@angular/core';
const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { NzModalRef, NzFormatEmitEvent, NzModalService, NzTreeComponent, NzTreeNodeOptions, NzMessageService } from 'ng-zorro-antd';
import { PagesService } from '../../services/pages.service';
import { UtilService } from '../../services/util.service';
import { RequestService } from '../../services/request.service';
declare var layui: any;
declare var layer: any;
declare var $: any;

@Component({
  selector: 'app-slc',
  templateUrl: './slc.component.html',
  styleUrls: ['./slc.component.scss']
})
export class SlcComponent implements OnInit {

  constructor(public router: Router, private http: HttpClient, public interfaceService: PagesService, public utilService: UtilService,public request:RequestService) {
    
  }

  @Output()  private  outer=new EventEmitter();
  @Input() puc_msg:any; 
  field1 = []     //table表格1-主表列字段集合
  data1 = {}      //table表格1-主表对象数据集合
  data1_dis = {}  //table表格1-主表对象禁用集合
  data1_sel = []  //table表格1-主表下拉框数据集合
  data1_att = []  //table表格1-主表自定义属性数据集合
  /**
   * 表格字段动态列集合生成
   */
  filed_tablelist() {
    this.interfaceService.postPage("/erp/common/fields/getfieldsbytype", { "type":"sales.SlcVo" }).subscribe((data: any) => {
      if (this.interfaceService.codeValidation(data)) {
      if(data.code==200){
        this.field1=this.utilService.filed_list4(data.object);
        this.popup01_table();//初始化列表表格数据
      }
    }
    });
  }
  unitStatus_list=JSON.parse(localStorage.getItem("unitStatus_list"))
  prodStatus_list=JSON.parse(localStorage.getItem("prodStatus_list"))
  srcDocType_list;
  pucType_list;
  slcType_list;
  acReqd_list;
  afReqd_list;
  prcSite_list;
  isCms_list;
  drDiffJgd_list;
  multiImpl_list;
  implByIns_list;
  puBrdgMode_list;
  slBrdgMode_list;
  isPuItmd_list;
  isSpot_list;
  psStlMthd_list;
  splEnabled_list;
  gmEnabled_list;
  mfzEnabled_list;
  bxiEnabled_list;
  rqdCtrl_list;
  psMfzSite_list;
  planCtrl_list;
  ordType_list;
  delivMthd_list;
  progress_list;
  psaCtlr_list;
  slcAutoGen_list;
  slcAutoChk_list;
  pucAutoGen_list;
  slcGen_list;
  pucAutoChk_list;
  isSlItmd_list;
  vdrInvd_list;
  vdeInvd_list;
  effective_list;
  suspended_list;
  cancelled_list;
  renewed_list;
  slCtrl_list;
  slFwdd_list;
  puCtrl_list

  ngOnInit() {
    this.filed_tablelist()
    setTimeout(()=>{ 
      this.interfaceService.postPage("/erp/purchase/prc/option",{}).subscribe((data0: any) => {//手动下拉
        if (data0.code == 200) {
          var sele = data0.object;
          /* this.srcDocType_list = sele.srcDocType1;// 原始单据类别
          this.pucType_list = sele.pucType;
          this.slcType_list = sele.slcType;
          this.acReqd_list = sele.acReqd;
          this.afReqd_list = sele.afReqd;
          this.prcSite_list = sele.prcSite;
          this.isCms_list = sele.isCms;
          this.drDiffJgd_list = sele.drDiffJgd;
          this.multiImpl_list = sele.multiImpl;
          this.implByIns_list = sele.implByIns;
          this.puBrdgMode_list = sele.puBrdgMode;
          this.slBrdgMode_list = sele.slBrdgMode;
          this.isPuItmd_list = sele.isPuItmd;
          this.isSpot_list = sele.isSpot;
          this.psStlMthd_list = sele.psStlMthd;
          this.splEnabled_list = sele.splEnabled;
          this.gmEnabled_list = sele.gmEnabled;
          this.mfzEnabled_list = sele.mfzEnabled;
          this.bxiEnabled_list = sele.bxiEnabled;
          this.rqdCtrl_list = sele.rqdCtrl;
          this.psMfzSite_list = sele.psMfzSite;
          this.planCtrl_list = sele.planCtrl;
          this.ordType_list = sele.ordType;
          this.delivMthd_list = sele.delivMthd;
          this.psaCtlr_list = sele.psaCtlr;
          this.slcAutoGen_list = sele.slcAutoGen;
          this.slcAutoChk_list = sele.slcAutoChk;
          this.pucAutoGen_list = sele.pucAutoGen;
          this.slcGen_list = sele.slcGen;
          this.pucAutoChk_list = sele.pucAutoChk;
          this.isSlItmd_list = sele.isSlItmd;
          this.vdrInvd_list = sele.vdrInvd;
          this.vdeInvd_list = sele.vdeInvd;
          this.effective_list = sele.effective;
          this.suspended_list = sele.suspended;
          this.cancelled_list = sele.cancelled;
          this.renewed_list = sele.renewed;
          this.slCtrl_list = sele.slCtrl;
          this.slFwdd_list = sele.slFwdd;
          this.puCtrl_list = sele.puCtrl; */
          this.progress_list = sele.progress;
        }
      });
    },500);
  }

  popup01_url='';
  popup01_switchUnitId='';
  popup01 = false;
  popup01_show(url,switchUnitId): void {
    this.popup01_url=url
    this.popup01_switchUnitId=switchUnitId;
    this.popup01 = true;
    this.popup01_table();
  }

  popup01_hide(): void {
    this.popup01 = false;
    this.popup01_url='';
    this.popup01_ss1='';
    this.popup01_ss2='';
    this.popup01_ss3=''; 
    this.popup01_ss4=''; 
    this.popup01_ss5 = '';
    this.popup01_ss6 = '';
    this.popup01_ss7 = null;
  }

  venderIdss='';
  popup01_ss1='';
  popup01_ss2='';
  popup01_ss3='';
  popup01_ss4='';
  popup01_ss5 = '';
  popup01_ss6 = '';
  popup01_ss7 = null;
  popup01_table(){
    var jindu = this.popup01_ss7
    if (this.popup01_ss7 == null) {
      jindu = ""
    } else {
      jindu = this.popup01_ss7
    }
    this.popup01_listTable(this.popup01_url + "?1=1&slcNum=" + this.popup01_ss1 + "&startTime=" + this.popup01_ss2 + "&endTime=" + this.popup01_ss3 + "&vendeeNum=" + this.popup01_ss4 + "&vdeWarehNum=" + this.popup01_ss5 + "&vdrWarehNum=" + this.popup01_ss6 + "&progress=" + jindu + "&switchUnitId=" + this.popup01_switchUnitId);
  }
  indexTableId = 'popup01_tblist_slc'
  popup01_listTable(url):void{
    setTimeout(()=>{ 
      layui.use(['table',  'laydate'], (obj)=>{
        var  table = layui.table,  laydate = layui.laydate;
        laydate.render({
          elem: '#popup011_ss2' 
          ,done: (value) => {
            this.popup01_ss2=value; 
          }
        });
        laydate.render({
          elem: '#popup011_ss3' 
          ,done: (value) => {
            this.popup01_ss3=value; 
          }
        });
        var tab = this.utilService.getTable(url, "#" + this.indexTableId, this.field1)
        tab["title"] = '销售合同弹窗数据表'
        table.render(tab);
        table.on('rowDouble(popup01_tblist_slc)', (obj)=>{
          this.popup01_hide();
          this.outer.emit(obj.data)       
         });
        
      });
      
    },50);
  
  }


  
@ViewChild('unit2Child')  unit2:any; //组织
popup0_id=0
popup0_url=""
popup0_show(id,type): void {
  this.popup0_id=id
  this.popup0_url="&unitType="+type+"&switchUnitId=" + this.popup01_switchUnitId
  if (this.popup0_id == 1) {
    this.popup0_url="&switchUnitId=" + this.popup01_switchUnitId
  } else if (this.popup0_id == 2) {
    this.popup0_url="&switchUnitId=" + this.popup01_switchUnitId
  } else if (this.popup0_id == 3) {
    this.popup0_url="&switchUnitId=" + this.popup01_switchUnitId
  }
  this.unit2.popup01_show("/erp/unit/option/unitOption?unitType="+type+this.popup0_url);
}

unit2Parent(e){		//接收子组件传递过来的数据
  if (this.popup0_id == 1) {
    this.popup01_ss4  = e.unitCode;
  } else if (this.popup0_id == 2) {
    this.popup01_ss5  = e.unitCode;
  } else if (this.popup0_id == 3) {
    this.popup01_ss6  = e.unitCode;
  }
}



}
